package com.fms.sys.controller;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import com.fms.common.vo.Result;

@RestController
@RequestMapping("/upload")
public class UploadController {
    @PostMapping
    public Result<String> uploadFile(@RequestParam("file") MultipartFile file) {
        if (file.isEmpty()) {
            return Result.fail("文件为空");
        }
        try {
            // 保存文件到 F 盘 uploads 目录
            String fileName = file.getOriginalFilename();
            String filePath = "F:/uploads/" + fileName;
            File dest = new File(filePath);
            file.transferTo(dest);
            // 返回前端可访问的路径
            return Result.success("/uploads/" + fileName, "上传成功");
        } catch (IOException e) {
            return Result.fail("上传失败");
        }
    }
}